//
//  TextFieldController.m
//  BSProject
//
//  Created by nsm on 2019/8/29.
//  Copyright © 2019 beisheng. All rights reserved.
//

#import "TextFieldController.h"

@interface TextFieldController ()

@end

@implementation TextFieldController

#pragma mark - lifeCycle

#pragma mark - override

#pragma mark - initialization
- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSMTextField *tf = NSMTextField.new;
    tf.backgroundColor = UIColor.yellowColor;
    tf.size = CGSizeMake(kScreenWidth-60, 44);
    tf.center = CGSizeCenter(kScreenSize);
    tf.top = 44;
    tf.maximumLength = 5;
    tf.textColor = COLOR_0;
    tf.placeholderColor = UIColor.redColor;
    tf.placeholder = @"卧槽";
    tf.placeholderFont = CustomFont(12);
    tf.contentEdgeInsets = UIEdgeInsetsMake(20, 20, 0, 20);
    tf.font = CustomFont(15);
    [self.view addSubview:tf];
    
    tf.textDidChange = ^(NSMTextField * _Nonnull textField) {
        NSLog(@"文字改变了[%lu]:%@", (unsigned long)textField.text.length, textField.text);
    };
    tf.textDidIntercept = ^(NSMTextField * _Nonnull textField) {
        NSLog(@"文字被截断了[%lu]:%@", (unsigned long)textField.text.length, textField.text);
    };
    
    UIView *view = UIView.new;
    view.size = CGSizeMake(100, 34);
    
    NSMSMSButton *button = NSMSMSButton.new;
    button.size = view.size;
    button.titleLabel.font = SystemFont(15);
    button.normalTitleColor = COLOR_0;
    button.normalBackgroundColor = COLOR_4;
    @nsm_weak(self)
    button.onActionHandler = ^(void (^completion)(BOOL)) {
        @nsm_strong(self)
        completion(YES);
    };
    
    [button reloadAndUpdate];
    [view addSubview:button];
    
    tf.rightView = view;
    tf.rightViewMode = UITextFieldViewModeAlways;
    
    
    UITextView *textView = UITextView.new;
    textView.size = CGSizeMake(200, 200);
    textView.top = tf.bottom+20;
    textView.centerX = tf.centerX;
    [self.view addSubview:textView];
    
    NSString *htmlStr = @"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>     <title>跳转中...</title>    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no\" />    <script type=\"text/javascript\" src=\"/Scripts/jquery-1.8.3.min.js\"></script>    <script src=\"/Scripts/layer/layer.js\"></script>        <script type=\"text/javascript\">                function ok() {                    $(\"form\")[0].submit();                }        </script></head><body><div style=\"width:100%;text-align:center;margin-top:100px;\"><span style=\"color:Green;font-size:15px;\">页面执行中，请勿关闭或刷新页面...</span></div>        <form action=\"http://api.otcbank.net/pay/createPayOrder\" method=\"POST\">            <input type=\"hidden\" name=\"businessId\"  value=\"10217\"/>            <input type=\"hidden\" name=\"signType\"  value=\"MD5\"/>            <input type=\"hidden\" name=\"amount\"  value=\"1000.00\"/>            <input type=\"hidden\" name=\"outTradeNo\"  value=\"17424641191011095319\"/>            <input type=\"hidden\" name=\"random\"  value=\"132152323979478890\"/>            <input type=\"hidden\" name=\"payMethod\"  value=\"5\"/>            <input type=\"hidden\" name=\"dataType\"  value=\"1\"/>            <input type=\"hidden\" name=\"notifyUrl\"  value=\"http://ybb488.com/Pay/notify/276\"/>            <input type=\"hidden\" name=\"returnUrl\"  value=\"http://angelpay6.com/Pay/success/276\"/>            <input type=\"hidden\" name=\"sign\"  value=\"5363340e4a68a47b6bb4a220f59fb862\"/>                </form>               <script type=\"text/javascript\">           ok();       </script></body></html>";
    htmlStr = @"真人视讯 <br />    真人视讯";
    NSData *data = [htmlStr dataUsingEncoding:NSUnicodeStringEncoding];
    NSDictionary *options = @{NSDocumentTypeDocumentOption: NSHTMLTextDocumentType};
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];
    [attr addAttributes:@{NSFontAttributeName: CustomFont(14)} range:NSMakeRange(0, attr.string.length)];
    textView.attributedText = attr;
}

#pragma mark - setter/getter

#pragma mark - network

#pragma mark - method/public

#pragma mark - method/private

#pragma mark - action

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
